package com.xiaomazi.ucenter.controller;

import com.xiaomazi.ucenter.service.UcenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: llxy-parent
 * @description: 微信接口前端控制器
 * @author: 小马子
 * @create: 2023-02-28 15:39
 **/
@Controller
@RequestMapping("/api/ucenter/wx")
public class WechatController {
    @Autowired
    private UcenterService ucenterService;

    //1 生成微信扫描二维码
    @GetMapping("login")
    public String getWxCode() {
        String wechatCodeURL = ucenterService.generateWechatCode();
        return "redirect:"+wechatCodeURL;
    }

    //2 获取扫描人信息，添加数据
    @GetMapping("callback")
    public String callback(String code, String state) {
        String authentication = ucenterService.getWechatUserInfo(code,state);
        return "redirect:http://localhost:3000?authentication="+authentication;
        //return authentication;
    }
}

